﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Hospital.BLL.IBLL;
using Hospital.Model;
using Hospital.BLL.BLLImpl;
using Spring.Context.Support;

namespace Hospital.Web.Master
{
    public partial class Master : System.Web.UI.MasterPage
    {
        private IUserService userService;

        public IUserService UserService
        {
            set { userService = value; }
            get { return userService; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            UserService = new UserServiceImpl();
            var webApplicationContext =
                           ContextRegistry.GetContext() as WebApplicationContext;
            UserService =
                webApplicationContext.GetObject("UserService") as IUserService;//从spring配置中获取Userservice
            User user = userService.UserLogin(tbUserName.Text.Trim(), tbPassword.Text.Trim());
            if (user != null)
            {
                Session["User"] = user;
            }
            else
            {
                this.lMsg.Text = "用户名或者密码错误，请重新输入！";
            }
        }
    }
}
